<?
include_once("./root.inc.php");
include_once("${root}/mysql/database_info.php");
include_once("${root}/mysql/common.php");
include_once("${root}/common.php");
connect_select_test("Registration-".$_REQUEST['id']);
$query = "SELECT 'id',
				'names',
				'numRegistered',
				'phone',
				'email',
				'notes',
				'paymentType',
				'amountPaid',
				'paidFull',
				'scholarship',
				'donation',
				'amountOwe'
				 UNION 
				 SELECT * FROM `Registration-".$_REQUEST["id"]."`
				 ";
$x = mysql_query($query);
if ($x){
	header('Content-disposition: attachment; filename='.$_REQUEST['id'].'.csv');
	header('Content-type: application/csv');
	while ($row = mysql_fetch_array($x)){
		for ($y=0;$y<(count($row)/2);$y++){
			printf("\"%s\"", $row[$y]);
			if ($y != ((count($row)/2)-1)){
				printf(",");
			}
		}
		printf("\n");
	}
	readfile("/home3/southhi9/public_html/".$_REQUEST['id'].".csv");
	unlink("/home3/southhi9/public_html/".$_REQUEST['id'].".csv");	
} else {
	printf("<script type='text/javascript'>alert(\"Failure\" + $query);</script>");
}
?>